import socket,time
def get_host_latency(host,port):
    """return remote service latency in ms or an 2-tuple error"""
    try:
        sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        sock.settimeout(1) # set a one second timeout
        start = time.time()
        sock.connect((host,port))
        end = time.time()
        print sock.getsockname()
        sock.close() # --> useless
        return int(( end - start ) * 1000)
    except socket.error, error:
        return error
    
#print get_host_latency('google.com',80)